package com.cn.jinl.controller;

import com.cn.jinl.api.IAbandonMaterialHandleService;
import com.cn.jinl.domain.AbandonMaterialHandle;
import com.cn.jinl.domain.AbandonVo;
import com.cn.jinl.domain.AbandonYearVo;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/abandonHandle")
public class AbandonMaterialHandleController {

    @Autowired
    private IAbandonMaterialHandleService abandonMaterialHandleService;

    @RequestMapping("/getAbandonMaterialHandleList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<AbandonMaterialHandle>> getAbandonMaterialHandleList(QueryForm queryForm, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<List<AbandonMaterialHandle>> response = new JsonResponse<List<AbandonMaterialHandle>>();
        List<AbandonMaterialHandle> list = abandonMaterialHandleService.getAbandonMaterialHandleList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getAbandonVoList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<AbandonVo>> getAbandonVoList( @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<List<AbandonVo>> response = new JsonResponse<List<AbandonVo>>();
        List<AbandonVo> list = abandonMaterialHandleService.getAbandonVoList();
        response.setResult(list);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getAbandonPercentList/{frontToken}")
    @ResponseBody
    public JsonResponse<Map<String,Object>> getAbandonPercentList( QueryForm queryForm,@PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<Map<String,Object>> response = new JsonResponse<Map<String,Object>>();
        Map<String,Object> result = abandonMaterialHandleService.getAbandonPercentList(queryForm);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getAbandonYearVoList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<AbandonYearVo>> getAbandonYearVoList(String year, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<List<AbandonYearVo>> response = new JsonResponse<List<AbandonYearVo>>();
        List<AbandonYearVo> result = abandonMaterialHandleService.getAbandonYearVoList(year);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/addBatchAbandonMaterialHandles/{frontToken}")
    public JsonResponse<String> addBatchAbandonMaterialHandles(@RequestBody List<AbandonMaterialHandle> abandonMaterialHandles, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = abandonMaterialHandleService.addBatchAbandonMaterialHandles(abandonMaterialHandles);
        return CommonUtil.getResponseData(response, result);
    }
}
